package pers.wq.controller;

import java.util.Map;
import java.util.Calendar;
import java.util.List;
import pers.wq.model.MyModel;
import pers.wq.model.SelectMajorModel;
import pers.wq.util.StringUtil;

public class BaseListData {
	public static final String WQ_TAG_CID = "##WQ_CID##";
	public static final String WQ_TAG_TIME_WEIGHT = "##WQ_TIME_WEIGHT##";
	public static final String WQ_TAG_SID = "##WQ_SID##";
	public static final int SUB_WEIGHT = 5; 
	public static final int ALL_SELECT_NUM = 3;
	private String[] thList;
	private String[] thNameList;
	private String table;
	private String title;
	private String condition;
	private int id;
	private List<Map<String,String>> trItemList;
	private boolean cancelAdd = false;
	private boolean cancelEdit = false;
	private boolean cancelDelete = false;
	
	public boolean initTrItemList(){
		String thName = StringUtil.splice(thNameList);
		if(StringUtil.strIsNull(thName) && StringUtil.strIsNull(table)){
			return false;
		}
		
		if(getId() != 0){
			System.out.println("BaseListData initTrItemList");
			System.out.println(condition);
			condition = condition.replace(WQ_TAG_CID, getId()+"");
			condition = condition.replace(WQ_TAG_SID, getId()+"");
			List<Map<String,String>> listMap= MyModel.selectMap("tid", "time", "time>0", "1", "tid desc");
			int tid = 1;
			if(null != listMap && listMap.size() == 1) {
				tid = Integer.parseInt(((Object)(listMap.get(0).get("tid"))).toString());
			}
			if(condition.contains(WQ_TAG_TIME_WEIGHT)) {
				SelectMajorModel smm = new SelectMajorModel();
				this.trItemList = smm.getSortList(getId(),SUB_WEIGHT - tid);
				if(MyModel.checkList(this.trItemList)) {
					return true;
				}
			}
		}
		
		this.trItemList = MyModel.selectMap(thName, table, condition, null, null);
		if(MyModel.checkList(trItemList)){
			return true;
		}
		return false;
	}
	public String getTable() {
		return table;
	}
	public void setTable(String table) {
		this.table = table;
	}
	public void setThNameList(String[] thNameList){
		this.thNameList = thNameList;
	}
	public String[] getThNameList(){
		return this.thNameList;
	}
	public String[] getThList() {
		return thList;
	}
	public void setThList(String[] thList) {
		this.thList = thList;
	}
	public List<Map<String, String>> getTrItemList() {
		return trItemList;
	}
	public void setTrItemList(List<Map<String, String>> trItemList) {
		this.trItemList = trItemList;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getTitle() {
		return title;
	}
	public String getCondition() {
		return condition;
	}
	public void setCondition(String condition) {
		this.condition = condition;
	}
	public boolean isCancelAdd() {
		return cancelAdd;
	}
	public void setCancelAdd(boolean cancelAdd) {
		this.cancelAdd = cancelAdd;
	}
	public boolean isCancelEdit() {
		return cancelEdit;
	}
	public void setCancelEdit(boolean cancelEdit) {
		this.cancelEdit = cancelEdit;
	}
	public boolean isCancelDelete() {
		return cancelDelete;
	}
	public void setCancelDelete(boolean cancelDelete) {
		this.cancelDelete = cancelDelete;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
}
